import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const SET_NUM = "SET_NUM"

let state = {
  num: 10
}

let mutations = {
  [SET_NUM](state,num){
    console.log(state)
  }
}

let actions = {
  getNum({commit}){
    // console.log('about-actions')
    commit('SET_COUNT',null,{root:true})   // 提交全局mutations
  },
  rootAction:{
    root:true,   // 注册到全局上
    handler(context,num){
        console.log('about-action')
    }
  }
}

let getters = {
  numGetters(state,getters,rootState,rootGetters){
    // console.log(state)
    // console.log(getters)
    // console.log(rootState)
    // console.log(rootGetters)
    return state.num
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
